home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir41 / ucpbtm10.zip / UCOMPBTM.8 < prev    next >
Text File  |  1993-12-23  |  8KB  |  440 lines

  1. ; UCOMPBTM 4dos compressed .BTM decompressor
  2. ; Copyright (C) 1933 Christopher Hall
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program, as the file COPYING.DOC; if not, write to the
  16. ; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ; I may be contacted by e-mail as cah17@phx.cam.ac.uk, or by paper mail at
  19. ; Christ's College, Cambridge, CB2 3BU, England
  20.  
  21. main:
  22.   jmp start
  23.  
  24. common_chars equ main-2
  25.  
  26. help:
  27.   mov dx,t_help
  28.   jmp error_exit
  29.  
  30. check_space:
  31.   cmp al,' '
  32.   je ret
  33.   cmp al,9
  34.   je ret
  35.   cmp al,'='
  36.   je ret
  37.   cmp al,';'
  38.   ret
  39.  
  40. parse:
  41.   mov si,081
  42.   xor bx,bx                     ;input filename
  43.   xor cx,cx                     ;output filename
  44.   xor dl,dl                     ;no /O found
  45.  l0:
  46.   lodsb
  47.   call check_space
  48.   je l0
  49.   cmp al,0d
  50.   je ret
  51.   cmp al,'/'
  52.   jne >l1
  53.   cmp b[si],'?'
  54.   je help
  55.   cmp b[si],'o'
  56.   je >l2
  57.   cmp b[si],'O'
  58.   jne >l1
  59.  l2:
  60.   mov al,b[si+1]
  61.   cmp al,0d
  62.   je help
  63.   call check_space
  64.   mov al,'/'
  65.   jne >l1
  66.   mov dl,1
  67.   add si,2
  68.  l0:
  69.   lodsb
  70.   call check_space
  71.   je l0
  72.   cmp al,0d
  73.   je help
  74.  l1:
  75.   lea bx,[si-1]
  76.  l0:
  77.   lodsb
  78.   cmp al,0d
  79.   je >l1
  80.   call check_space
  81.   jne l0
  82.  l1:
  83.   mov b[si-1],0
  84.   cmp al,0d
  85.   je >l9
  86.  l0:
  87.   lodsb
  88.   call check_space
  89.   je l0
  90.   cmp al,0d
  91.   je >l9
  92.   lea cx,[si-1]
  93.  l0:
  94.   lodsb
  95.   cmp al,0d
  96.   je >l1
  97.   call check_space
  98.   jne l0
  99.  l1:
  100.   mov b[si-1],0
  101.  l9:
  102.   jcxz >l1
  103.   ret
  104.  
  105.  l1:
  106.   mov cx,di,si
  107.   mov si,bx
  108.   xor bp,bp                             ;position after dot.
  109.  l0:
  110.   lodsb
  111.   stosb
  112.   or al,al
  113.   je >l1
  114.   cmp al,'\'
  115.   if e xor bp,bp
  116.   cmp al,'.'
  117.   if e mov bp,di
  118.   jmp l0
  119.  l1:
  120.   or bp,bp
  121.   jnz >l1
  122.   dec di
  123.   mov al,'.'
  124.   stosb
  125.   jmp >l2
  126.  l1:
  127.   mov di,bp
  128.  l2:
  129.   mov ax,[di]
  130.   and ax,0dfdf
  131.   cmp ax,'AB'
  132.   jne >l1
  133.   mov al,[di+2]
  134.   and al,0df
  135.   cmp al,'T'
  136.   je same_name
  137.  l1:
  138.   mov ax,'ab'
  139.   stosw
  140.   mov ax,'t'
  141.   stosw
  142.   ret
  143.  
  144. same_name:
  145.   call print_names
  146.   mov dx,t_same_name
  147.   jmp error_exit
  148.  
  149. print_string:
  150.   push si,cx
  151.   xor cx,cx
  152.   mov si,dx
  153.  l0:
  154.   lodsb
  155.   inc cx
  156.   or al,al
  157.   jnz l0
  158.   dec cx
  159.   jcxz >l9
  160.   push ax,bx
  161.   mov ah,040
  162.   mov bx,2
  163.   int 021
  164.   pop bx,ax
  165.  l9:
  166.   pop cx,si
  167.   ret
  168.  
  169. in_handle dw 0
  170. out_handle dw 1
  171.  
  172. do_hi:
  173.   xor bl,bl                             ;reset flag
  174.   xchg al,bl                            ;bh is always 0 here
  175.   mov bl,[common_chars+bx+16]
  176.   xchg al,bl
  177.   jmp put_byte
  178.  
  179. lit_1:
  180.   inc bh
  181.   mov dl,al
  182.   ret
  183.  
  184. lit_2:
  185.   xor bh,bh
  186.   shl al,1
  187.   shl al,1
  188.   shl al,1
  189.   shl al,1
  190.   or al,dl
  191.   jmp put_byte
  192.  
  193. do_byte:
  194.   cmp bl,1
  195.   je do_hi
  196.   cmp bh,1
  197.   je lit_1
  198.   cmp bh,2
  199.   je lit_2
  200.   or al,al
  201.   jne >l1
  202.   mov bh,1
  203.   ret
  204.  l1:
  205.   cmp al,1
  206.   jne >l1
  207.   mov bl,1
  208.   ret
  209.  l1:
  210.   xchg al,bl                            ;bh is always 0 here
  211.   mov bl,[common_chars+bx]
  212.   xchg al,bl
  213.  
  214. put_byte:
  215.   dec cx
  216.  l0:
  217.   stosb
  218.   cmp di,01234
  219. outbuf_end equ w[$-2]
  220.   jne >l2
  221. flush:
  222.   push ax,bx,cx,dx
  223.   mov ah,040
  224.   mov bx,out_handle
  225.   mov cx,di
  226.   mov dx,01234
  227. outbuf_start equ w[$-2]
  228.   sub cx,dx
  229.   jcxz >l1
  230.   int 021
  231.  l1:
  232.   pop dx,cx,bx,ax
  233.   mov di,outbuf_start
  234.  l2:
  235.   cmp al,0d
  236.   if ne ret
  237.   mov al,0a
  238.   jmp l0
  239.  
  240.  l2:
  241.   jc ret
  242.   mov ah,al
  243.   jmp get_byte
  244. get_word:
  245.   push l2
  246. get_byte:
  247.   cmp si,bp
  248.   je >l1
  249.   lodsb
  250.   clc
  251.   ret
  252.  l1:
  253.   push ax,bx,cx,dx
  254.   mov ah,03f
  255.   mov bx,in_handle
  256.   mov cx,01234
  257. inbuf_len equ w[$-2]
  258.   mov dx,eop
  259.   mov bp,dx
  260.   int 021
  261.   if c xor ax,ax
  262.   add bp,ax
  263.   mov si,eop
  264.   pop dx,cx,bx,ax
  265.   lodsb
  266.   cmp bp,si                             ;eof=>stc
  267.   ret
  268.  
  269.  l0:
  270.   mov dx,t_stdio
  271.   call print_string
  272.   ret
  273.  
  274. print_names:
  275.   push dx
  276.   mov dx,t_decompressing
  277.   call print_string
  278.   mov dx,bx
  279.   call print_string
  280.   mov dx,t_to
  281.   call print_string
  282.   mov dx,cx
  283.   call print_string
  284.   mov dx,t_crlf
  285.   call print_string
  286.   pop dx
  287.   ret
  288.  
  289. open_files:
  290.   cmp bx,cx
  291.   je l0
  292.   call print_names
  293.   or dl,dl
  294.   jne >l2
  295.   push bx,cx,dx
  296.   mov dx,cx
  297.   mov ax,03d00
  298.   int 021
  299.   jc >l1
  300.   mov bx,ax
  301.   mov ah,03e
  302.   int 021
  303.   mov dx,t_overwrite_error
  304.   jmp error_exit
  305.  l1:
  306.   pop dx,cx,bx
  307.  l2:
  308.   push cx
  309.   mov dx,bx
  310.   mov ax,03d00
  311.   int 021
  312.   jnc >l1
  313.   mov dx,t_openin_error
  314.   jmp error_exit
  315.  l1:
  316.   mov in_handle,ax
  317.   pop dx
  318.   mov ah,03c
  319.   xor cx,cx
  320.   int 021
  321.   jnc >l1
  322.   mov ah,03e
  323.   mov bx,in_handle
  324.   int 021
  325.   mov dx,t_openout_error
  326.   jmp error_exit
  327.  l1:
  328.   mov out_handle,ax
  329.   ret
  330.  
  331. close_files:
  332.   mov ah,03e
  333.   mov bx,in_handle
  334.   cmp bx,5
  335.   if ae int 021
  336.   mov in_handle,0
  337.   mov ah,03e
  338.   mov bx,out_handle
  339.   cmp bx,5
  340.   if ae int 021
  341.   mov out_handle,1
  342.   ret
  343.  
  344. error_exit:
  345.   call print_string
  346.   call close_files
  347.   mov ax,04cff
  348.   int 021
  349.  
  350. start:
  351.   mov dx,t_signon
  352.   call print_string
  353.   mov ax,sp
  354.   sub ax,0100
  355.   mov outbuf_end,ax
  356.   sub ax,eop
  357.   shr ax,1
  358.   mov inbuf_len,ax
  359.   add ax,eop
  360.   mov outbuf_start,ax
  361.   call parse
  362.   mov dx,t_howto_help
  363.   call print_string
  364.   call open_files
  365.   mov si,bp,eop
  366.   mov di,outbuf_start
  367.  
  368.   call get_word
  369.   cmp ax,0ebbe                  ;is it compressed?
  370.   mov dx,t_not_compressed
  371.   jne error_exit
  372.   call get_word
  373.   xchg ah,al
  374.   mov cx,ax                     ;length of uncompressed file
  375.   push cx,di
  376.   mov cx,30
  377.   mov di,common_chars+2
  378.  l0:
  379.   call get_byte
  380.   jc >l9
  381.   stosb
  382.   loop l0
  383.   pop di,cx
  384.   xor bx,bx                     ;bh=1 for literal; bl=1 for second 16 chars
  385.  l0:
  386.   call get_byte
  387.   jc >l1
  388.   mov ah,al
  389.   shr al,1
  390.   shr al,1
  391.   shr al,1
  392.   shr al,1
  393.   and ah,0f
  394.   call do_byte
  395.   jcxz >l1
  396.   mov al,ah
  397.   call do_byte
  398.   inc cx
  399.   loop l0
  400.  l1:
  401.   call flush
  402.  l9:
  403.   call close_files
  404.   mov ax,04c00
  405.   int 021
  406.  
  407. t_not_compressed: db 'File is not a compressed batch file',0d,0a,0
  408.  
  409. ;; We can write data over the remaining messages, as they can't be issued after
  410. ;; reading from the file.
  411. eop:
  412.  
  413. t_decompressing: db 'Decompressing ',0
  414. t_to: db ' to ',0
  415. t_stdio: db 'Decompressing STDIN to STDOUT',0d,0a,0
  416. t_overwrite_error: db 0d,0a
  417.   db 'UCOMPBTM failed: That would overwrite an existing file!',0d,0a
  418.   db 'Use the /O switch to force overwriting.',0d,0a,0
  419. t_openin_error: db 0d,0a
  420.   db 'UCOMPBTM failed: Can''t open input file!',0d,0a,0
  421. t_openout_error: db 0d,0a
  422.   db 'UCOMPBTM failed: Can''t open output file!',0d,0a,0
  423. t_same_name: db 0d,0a
  424.   db 'UCOMPBTM failed: Input and output files must have different names!',0d,0a,0
  425. t_help:
  426.   db 0d,0a
  427.   db 0d,0a
  428.   db 'UCOMPBTM comes with ABSOLUTELY NO WARRANTY; for details see the GNU',0d,0a
  429.   db 'GPL in the file COPYING.DOC which should have come with this program.',0d,0a
  430.   db 'If this file is missing, write to the Free Software Foundation, Inc.,',0d,0a
  431.   db '675 Mass Ave, Cambridge, MA 02139, USA.',0d,0a
  432.   db 0d,0a
  433.   db 'Usage:  UCOMPBTM [[/O] input_file [output_file]]',0d,0a,0
  434. t_signon: db 0d,0a
  435.   db 'UCOMPBTM 1.0  Copyright (C) 1993 Christopher Hall',0
  436. t_howto_help:
  437.   db '  UCOMPBTM /? for help',0d,0a
  438. t_crlf:
  439.   db 0d,0a,0
  440.